package br.com.pb.bymychef.persistencia.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="tb_crawler")
@SequenceGenerator(name = "S_TB_CRAWLER", sequenceName = "S_TB_CRAWLER", initialValue = 0, allocationSize = 1)
public class Crawler implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "S_TB_CRAWLER")
    @Column(name="idCrawler")
    private Long idCrawler;
    @Column(name="nome", length=80, nullable=false)
    private String nome;
    @Column(name="descricao", length=150, nullable=false)
    private String descricao;
    @Column(name="siteCapturacao", length=100, nullable=false)
    private String siteCapturacao;
    @OneToMany(mappedBy="crawler", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    private List<ReceitaCrawler> receitasCrawler;
    
    
    public Crawler() {
	super();
    }
    
    public Crawler(String nome, String descricao, String siteCapturacao) {
	super();
	this.nome = nome;
	this.descricao = descricao;
	this.siteCapturacao = siteCapturacao;
    }
    
    public Long getIdCrawler() {
        return idCrawler;
    }
    
    public void setIdCrawler(Long idCrawler) {
	this.idCrawler = idCrawler;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public String getSiteCapturacao() {
        return siteCapturacao;
    }

    public void setSiteCapturacao(String siteCapturacao) {
        this.siteCapturacao = siteCapturacao;
    }

    
    public List<ReceitaCrawler> getReceitasCrawler() {
        return receitasCrawler;
    }

    public void setReceitasCrawler(List<ReceitaCrawler> receitasCrawler) {
        this.receitasCrawler = receitasCrawler;
    }
    
    public void addReceita(ReceitaCrawler receitaCrawler) {
	
	if(this.receitasCrawler == null)
	    this.receitasCrawler = new ArrayList<ReceitaCrawler>();
	this.receitasCrawler.add(receitaCrawler);
	
    }
    
    public void removeReceita(ReceitaCrawler receitaCrawler) {
	
	if(this.receitasCrawler != null)
	    this.receitasCrawler.remove(receitaCrawler);
	
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result
		+ ((idCrawler == null) ? 0 : idCrawler.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Crawler other = (Crawler) obj;
	if (idCrawler == null) {
	    if (other.idCrawler != null)
		return false;
	} else if (!idCrawler.equals(other.idCrawler))
	    return false;
	return true;
    }
    
}
